<script>
    var enable_submit = true;
    function submit_folder_create(){
    var load_name= $("#folder_create_modal").find("#load_this_name");
    var access_policy= $("#folder_create_modal").find("#folder_ap_select");
    var folder_quot = $("#folder_create_modal").find("#folder_quot");
    var delete_code = $("#folder_create_modal").find("#delete_code");
    var delete_code_r = $("#folder_create_modal").find("#delete_code_r");
    var repnum = $("#folder_create_modal").find("#repnum");

    var bValid = true;
    bValid = bValid && checkNull(load_name, "请输入文件夹名称");
    bValid = bValid && checkRegexp(load_name, /^[0-9a-z-:]{1,32}$/, "名称必须由1至32位小写英文字母、数字、中划线或冒号构成");
    if($(".repnum").is(":hidden")){
        repnum.attr("realvalue","");
    }
//    if($(".code_delete_op").is(":hidden")){
    if ($("#folder_create_modal").find(".pool_rep_delete").is(":checked") == false) {
        delete_code.attr("realvalue","");
        delete_code_r.attr("realvalue","");
    }


    if (bValid) {
        if(enable_submit) {
            enable_submit = false;
            var $submitBtn = $('.modal-footer').find('.btn-blue');
            $submitBtn.html('<i class="fa fa-spinner fa-spin" style="margin:3px 6px;"></i>');
            $('.rtn-tip').slideUp('fast');
            var folder_data = {
                "folder_name": $.trim(load_name.val()),
                "access_policy_id":$.trim(access_policy.attr('realvalue')),
		"repnum": $.trim(repnum.attr("realvalue")),
                "ec_code": $.trim(delete_code_r.attr("realvalue")),
                "ec_data": $.trim(delete_code.attr("realvalue"))
            };
            $.post("/folder/create", folder_data,
                function(data){
                    if (data.reply.is_success)
                    {
                        angular.element('#folder_controller').scope().close();
                        $('#volume_folder_tb').trigger("reloadGrid")
                    }else
                    {
                        error =  data.reply.error;
                        $('.rtn-tip').text(error).slideDown('fast');
                        $submitBtn.html(SelfTranslate("[[ 'label ok'|translate ]]"));
                        enable_submit = true;
                    }
                });
        }

    }
}
    $(function() {
    	$('#folder_create_modal #repnum').rqDropDown({
    	    "datatype":"local",
    	    "source":get_repnums(),
    	    position:true
    	}); 

    	var delete_code = [['2', '2'],['3', '3'],['4', '4'],['6', '6'],['8', '8'],['12', '12'],['16', '16']];
    	$('#folder_create_modal #delete_code').rqDropDown({
    	    "datatype":"local",
    	    "source":delete_code
    	});
    	var delete_code_r = [['1', '1'],['2', '2'],['3', '3'],['4', '4']];
    	$('#folder_create_modal #delete_code_r').rqDropDown({
    	    "datatype":"local",
    	    "source":delete_code_r
    	});
    	if(val_payPlatform == "on"){
    	    var val_payPlatform = $('.pool_rep_rep[name="rep"]:checked ').val();
    	    $("#delete_code").removeAttr("id");
    	}

    	var repnum = $("#folder_create_modal").find("#repnum");
    	$(":checkbox").click(function() {
    	    if (($(this)).hasClass("pool_rep_rep") == true) {
    	        $(".repnum").show();
    	        $(".code_delete_op").hide();
    	    }
    	    if (($(this)).hasClass("pool_rep_delete") == true) {
    	        $(".code_delete_op").show();
    	        $(".repnum").hide();
    	    }
    	});

        var aps = [];

        {% for ap in access_policy %}
            var values = new Array();
            values[0] = "{{ ap.id }}";
            values[1] = "{{ ap.name }}";
            aps.push(values)
        {% endfor %}
        $('#folder_ap_select').rqDropDown({
            "datatype":"local",
            "source":aps,
            position:true
        });

        /* 为小图标绑定鼠标移入移出事件 */
        var obj = {
            'pool_name':'由1至32位小写英文字母、数字、中划线、冒号构成。'
        }
        bindMouseEvent('#folder_create_modal', obj);
        /* 为小图标绑定鼠标移入移出事件结束 */
    });
</script>
<style>
    .code_delete_op{
    /*    display: none; */
    }
</style>

<div class="modal-header">
    <h3>创建</h3>
</div>
<div class="modal-body modal-body-height" id="folder_create_modal">

    <div class="pool-create-box">
        <div class="rtn-tip"></div>
        <table class="base-info">
            <tr>
                <td>
                    <label>名称</label><a>*</a>
                </td>
                <td colspan="3">
                    <input id="load_this_name" type="text"/>
                    <i class="fa fa-question-circle" itype="pool_name"></i>
                </td>
            </tr>
            <tr>
		        <td>
		            <label for="protocol_type">保护策略:</label>
		        </td>
		        <td>
<!--		            
                            <label><input type="radio" checked="checked" name="rep" class="pool_rep_rep">[['replication number'|translate]]</label> 
-->
		            <label><input type="checkbox" name="rep" class="pool_rep_delete">纠删码</label>
		        </td> 
            </tr>
		    <tr>
<!--		            
		        <td class="repnum">
		            <label>[['replication number'|translate]]</label>
		        </td>
		        <td class="repnum" style="padding-right: 50px;"><input id="repnum" readonly="readonly" class="rounded_dropdown" value='2' realvalue="2"/></td>
-->
		
		        <td class="code_delete_op">
		            <label>[['replication number'|translate]]</label>
		        </td>
		        <td class="code_delete_op">
		                <input id="delete_code" style="width:40%;" readonly="readonly" class="rounded_dropdown" value='2' realvalue="2"/>
		            <b>+</b>
		                <input  id="delete_code_r" style="width:40%;" readonly="readonly" class="rounded_dropdown" value='1' realvalue="1"/>
		        </td>
            </tr>
            <tr style='display:none'>
                <td>
                    <label>访问策略</label>
                </td>
                <td>
                    <input id="folder_ap_select" readonly="readonly" class="rounded_dropdown" value='无保护策略' realvalue=""/>
                </td>
                <td>
                </td>
                <td>
                </td>
            </tr>
        </table>
    </div>
    <div class="error-tip">
        <p></p><span></span>
    </div>
    <div class="tip">
        <p></p><span></span>
    </div>
</div>
<div class="modal-footer">
    <button class="btn btn-blue" ng-click="ok()">[[ 'label ok'|translate ]]</button>
    <button class="btn btn-white" ng-click="cancel()">[[ 'label cancel'|translate ]]</button>
</div>

